package com.yoomiito.app.ui.search

import cn.droidlover.xdroidmvp.net.ApiException
import cn.droidlover.xdroidmvp.net.ApiSubscriber
import cn.droidlover.xdroidmvp.net.XApi
import com.yoomiito.app.base.AppConfig
import com.yoomiito.app.base.BaseActPresenter
import com.yoomiito.app.model.home.TaoBaoHotSearch
import com.yoomiito.app.net.YmApi
import com.yoomiito.app.showToast

class SearchPresenter(appConfig: AppConfig?): BaseActPresenter<SearchActivity?>(appConfig){

    fun getHotSearch(){
        YmApi.getYmService()
                .hotSearch()
                .compose(v?.bindToLifecycle())
                .compose(XApi.getApiTransformerData())
                .compose(XApi.getScheduler())
                .subscribe(object :ApiSubscriber<TaoBaoHotSearch>(){
                    override fun onSuccess(t: TaoBaoHotSearch?) {
                        v?.setHotSearch(t)
                    }

                    override fun onFail(error: ApiException?) {
                        error?.msg?.showToast()
                    }
                })
    }
}
//    public void searchGoods(String key){
//        if (NetworkUtils.checkNetPermission(getV())){
//            return;
//        }
//        YmApi.getYmService()
//                .searchGoods(key, "", 0,0)
//                .compose(getV().bindToLifecycle())
//                .compose(XApi.<List<GoodsInfo>>getApiTransformerData())
//                .compose(XApi.<List<GoodsInfo>>getScheduler())
//                .subscribe(new ApiSubscriber<List<GoodsInfo>>(handleException()) {
//                    @Override
//                    public void onSuccess(List<GoodsInfo> results) {
//                        getV().toShowList(results);
//                    }
//
//                    @Override
//                    public void onFail(ApiException error) {
//                        getV().showError();
//                    }
//                });
//    }
